import QtQuick 1.0
import "storage.js" as Storage
import com.nokia.meego 1.0
import com.meego.extras 1.0

PageStackWindow {
     id:rootWindow
     showStatusBar: true
    signal buttonClicked;

function begin(){buttonClicked()}
     
function kill(){con.kill()}
//kill
     
function settings(){

if (rdesktop.checked){var a="0"} else {var a="1"};
if (rphone.checked){var b="0"} else {var b="1"};
if (player.checked){var c="0"} else {var c="1"};
if (mode.checked){var d="0"} else {var d="1"};
var set=(a+b+c+d).toString();
var frames=sl2.value.toString();
var addr= ip.text;
var com=set+"\n"+frames+"\n"+addr;
con.savesettings(com);
banner0.show();

}
	
//Switch on off
Rectangle {id: page
    	   width: parent.width; height:parent.height;
    	   color: "black"
    	   anchors.horizontalCenter: parent.horizontalCenter; 
    	   anchors.verticalCenter:parent.verticalCenter;

Switch{id:switchComponent

anchors.verticalCenter:parent.verticalCenter;
anchors.horizontalCenter:parent.horizontalCenter;
 onCheckedChanged: {
        //if (checked) {
	//begin()}
	//else {kill()}
    //}

switchComponent.checked ? begin() : kill()
}
//end of switch
Text{id:text

 	color:"red"
	anchors.bottom: switchComponent.top
	anchors.horizontalCenter: switchComponent.horizontalCenter
		text: switchComponent.checked ? "GROUNDWORK ON" : "Press to Start"
    	   font.pixelSize: 30
    	   smooth:true}
   }
Button {
		anchors.bottom:page.bottom
		anchors.horizontalCenter:page.horizontalCenter
                text: "Settings"
                onClicked: sheet.open()
            }

 Sheet {
        id: sheet

        acceptButtonText: "Save"
        rejectButtonText: "Cancel"
        title: BusyIndicator {id:title;
            anchors.centerIn: parent; running: sheet.status == DialogStatus.Open;
        }


	Column {
                id: col2

                //anchors.verticalCenter: parent.verticalCenter
		anchors.topMargin:21
		anchors.bottom:parent.bottom
		anchors.horizontalCenter: parent.horizontalCenter
                spacing: 0
		

		Label { text: "Record Session to Desktop" ; color: "black"; }
                ButtonRow {id:a
                Button { id: rdesktop; text: "OFF"; }
                Button { id:rdon; text: "ON" ; }
            		  }
		Label { text: "Record Session to Phone" ; color: "black"}
                ButtonRow {id:b
                Button { id: rphone;text: "OFF"; }
                Button { id:rpon; text: "ON" ; }
            		  }
		Label { text: "Viewer" ; color: "black"; }
                ButtonRow {id:c
                Button { id: player; text: "MPLAYER" ; }
                Button { id:plon; text: "VLC" ; }
            		  }
		Label { text: "RAW MODE" ; color: "black" }
                ButtonRow {id:d
                Button { id: mode;text: "OFF";  }
                Button { id:mon; text: "ON"; 
			}

 Component.onCompleted: {
        // Initialize the database
        Storage.initialize();
        // Sets a value in the database
Storage.setSetting("rdesktop",rdesktop.checked);
Storage.setSetting("rphone",rphone.checked);
Storage.setSetting("player",player.checked);
Storage.setSetting("mode",mode.checked);
Storage.setSetting("slider",sl2.value);
Storage.setSetting("ip",ip.value);
        // Sets the textDisplay element's text to the value we just set
        Storage.getSetting("rdesktop") ? rdesktop.checked= true : rdon.checked=true
Storage.getSetting("rphone") ? rphone.checked =true: rpon.checked = true
Storage.getSetting("player") ? player.checked=true: plon.checked= true
 Storage.getSetting("mode") ? mode.checked=true: mon.checked= true
sl2.value=Storage.getSetting("slider")
    }
            		  }
TextField {id:ip
                
placeholderText: "Desktop IP Adress"
                        inputMethodHints: Qt.ImhDigitsOnly | Qt.ImhNoPredictiveText
                    }
Row {
                Label { text: sl2.value.toFixed(2) ; color: "green"; width: 80 }
                Label { visible: screen.currentOrientation == Screen.Landscape; width: page.textColumnWidth; wrapMode: Text.Wrap; text: "Frames per Second" }
		Label { visible: screen.currentOrientation == Screen.Portrait; width: page.textColumnWidth; wrapMode: Text.Wrap; text: "FPS" }
                Slider { id:sl2; stepSize:1 ; valueIndicatorVisible: true; minimumValue:10 ; maximumValue:30 ; width:384;value:14}
            }


            }
        onAccepted: settings() ;
        //onRejected: label.text = "Rejected!"
}
	InfoBanner{
                id: banner0
                text: "Settings Saved"
               
                timerShowTime: 1*1000
                topMargin: 70
                leftMargin: 8
                  }

 		}
}
